package org.factory.report.utils;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.FileNotFoundException;
import java.io.FileReader;

/**
 * @author Stranger
 * @version 1.0
 * @description: TODO
 * @date 2022/10/19 21:19
 */
public class DBUtils {

    private static String config = "src/main/resources/mybatisConfig.xml";

    private static SqlSessionFactory sessionFactory;

    static {
        try {
            sessionFactory = new SqlSessionFactoryBuilder().build(new FileReader(config));
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }

    public static SqlSession getSqlSession() {
        return sessionFactory.openSession();
    }

}
